package com.huahang.fashionpress.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huahang.fashionpress.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * @Author: 阿俊哥 王翰聪 高晓曦
 * @Date: 2019/8/20 15:08
 * @Version 1.0
 * @version 1.1
 * @version 1.2
 *
 * 更新
 * @since : 2019/08/23
 * @author : 高晓曦
 * 添加了插入用户方法
 *
 * @since : 2019/08/27
 * @author : 王翰聪
 * @version : 1.3
 * 添加了更新用户数据的方法
 */

@Repository
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from t_user where user_username = #{username}")
    User selectByUsername(String username);

    @Insert("insert into t_user(user_username,user_password,user_email,user_phone) value(#{username},#{password},#{email},#{phone}) ")
    boolean insertNewUser(String username,String password,String email,String phone);

    @Update("update t_user set (user_username, user_phone, user_email) values(#{userName}, #{userPhone}, #{userEmail})" +
            "where user_id=#{userID}")
    int updateUserInfoByUserID(String userName, String userPhone, String userEmail, Integer userID);

    @Update("update t_user set (user_password) values (#{password}) where user_id=#{userID}")
    int updateUserPassword(String password, Integer userID);

    /**
     * @author : 高晓曦
     * 添加了查找用户email和用户手机号的方法
     * @param email
     * @return
     */
    @Select("select * from t_user where user_email = #{email}")
    User selectByEmail(String email);

    @Select("select * from t_user where user_phone = #{phone}")
    User selectByPhone(String phone);
}